package cn.linkai.hadoop.hive;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class HiveClient {

    private Connection connection;

    @Before
    public void setUp(){
        connection=HiveConnection.getInstance();
    }

    @Test
    public void testSelect() throws SQLException {
//        String sql="select id,name from hive_us";
        String sql="select id,name from hive_us";
        PreparedStatement pst=connection.prepareStatement(sql);
        ResultSet rs=pst.executeQuery();
        while(rs.next()){
            int id=rs.getInt("id");
            String name=rs.getString("name");
            System.out.println(id+" "+name);
        }
    }

    @Test
    public void testInsert() throws SQLException {
        String sql="insert into hive_us values(7,'java api')";
        PreparedStatement pst=connection.prepareStatement(sql);
        System.out.println(pst.execute());
    }

    @Test
    public void testCreateable() throws SQLException {
        String sql="insert into hive_us values(7,'java api')";
        PreparedStatement pst=connection.prepareStatement(sql);
    }

    @After
    public void tearDown(){
        try {
            connection.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
